# Maintainer: Martell Malone <martellmalone@gmail.com>

pkgname=busybox
pkgver=1.23.2
pkgrel=1
pkgdesc="BusyBox: The Swiss Army Knife of Embedded Linux"
arch=('i686' 'x86_64')
url="https://busybox.net/"
license=('GPL2')
depends=('msys2-runtime')
install=busybox.install
source=("https://busybox.net/downloads/${pkgname}-${pkgver}.tar.bz2"
        "busybox-1.23.2-1.cygwin.patch"
        "msys2.config"
        "pwdW.patch")

sha256sums=('05a6f9e21aad8c098e388ae77de7b2361941afa7157ef74216703395b14e319a'
            '79f504821d8d44b4be4eacce32f965e3e3591deebc00289cdd421180ded7e571'
            'ed8a9a051e97bbf24348e10b6fe1b4330d06825fa9dfd6c08c2f737c1456bd4e'
            'fa18a8deef9464ffa29aa966489294c6587b395f61c179538630fbb8e384dfbe')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  patch -p1 -i ${srcdir}/busybox-1.23.2-1.cygwin.patch
  #patch -p1 -i ${srcdir}/pwdW.patch
  cp ${srcdir}/msys2.config ${srcdir}/${pkgname}-${pkgver}/.config
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  #make oldconfig
  #CFLAGS='-O2 -static-libgcc'
  make cygwin_defconfig
  make
  mv -v busybox_unstripped.exe busybox.exe
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  #install busybox
  mkdir -p ${pkgdir}/usr/bin
  cp ${srcdir}/${pkgname}-${pkgver}/busybox.exe ${pkgdir}/usr/bin

  # license
  install -m644 -D LICENSE ${pkgdir}/usr/share/licenses/${pkgname}/LICENSE
}
